#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm

import pymysql
from DBUtils.PooledDB import PooledDB
from..config.database_config import config
from..models.sc_model import Sc


pool = PooledDB(
    creator=pymysql,
    **config,
    maxconnections=10,
    mincached=2,
    blocking=True
)


# 根据学号和课程编号查询选课记录信息
def query_sc_by_sno_cno(sno, cno):
    try:
        connection = pool.connection()
        cursor = connection.cursor()
        sql = "SELECT * FROM sc WHERE Sno = %s AND Cno = %s"
        cursor.execute(sql, (sno, cno))
        result = cursor.fetchone()
        if result:
            sc = Sc(*result)
            cursor.close()
            return sc
        connection.close()
    except pymysql.Error as e:
        print(f"查询选课记录信息时出错: {e}")
    return None


#
